type Fn<T> = () => Promise<T>
/**手撕promise.all
 * @param functions  () => Promise
 */
function promiseAll<T>(functions: Fn<T>[]): Promise<T[]> {
    return new Promise((resolve, reject) => {
        const allRes: T[] = []
        let count = 0
        for (let i = 0; i < functions.length; i++) {
            functions[i]().then((res) => {
                allRes[i] = res
                count++
                if (count === functions.length) {
                    resolve(allRes)
                }
            }, (err) => {
                return reject(err)
            })
        }
    })
};
export default promiseAll